package app.softtech.freechat;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import app.softtech.freechat.database.ConstantsDB;
import app.softtech.freechat.database.DatabaseFriend;
import app.softtech.freechat.database.DatabaseHanler;
import app.softtech.freechat.database.DatabaseUser;

public class maintest extends Activity{

	String[] arrUrl;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
//		setContentView(R.layout.activity_test_layout);
		deleteDatabase(ConstantsDB.DATABASE_NAME);
		DatabaseHanler db = new DatabaseHanler(this);
		
		Log.d("Insert ", "Inserting user.......");
		db.insertDatabseUser(new DatabaseUser(1,"nguyenvannam", "nguyenvannam",
				"bbbb@yahoo.com", "11111", "http://androidexample.com/media/webservice/LazyListView_images/image0.png", 0, "chua co chi"));
		db.insertDatabseUser(new DatabaseUser(2,"le_hai_nam", "namcutlo",
				"aaaa@yahoo.com", "11111", "http://androidexample.com/media/webservice/LazyListView_images/image0.png", 0, "chua co chi"));	
				
		Log.d("LIST_USER", "------------------");		
		List<DatabaseUser> listuser;
		listuser = db.getAllDatabaseUser();
		String s="";
		for (DatabaseUser f : listuser) {
			s += " userid: " + f.getUserId() + " username: " + f.getUserName() + " pass: " + f.getPassword() +" \n";
		} 
		Log.d("List user: ", s);
		
		
		Log.d("INSERT ", "-------------Inserting friend of user----------------");		
		db.insertDatabaseFriend(new DatabaseFriend(2, 6, "ho_thang", "http://androidexample.com/media/webservice/LazyListView_images/image1.png",
				"abcs d", "073838383", "dang lam chi",11));
		db.insertDatabaseFriend(new DatabaseFriend(2, 7, "bao_an", "http://androidexample.com/media/webservice/LazyListView_images/image1.png", "adfd",
				"073838383", "dang ngoi choi",12));
		db.insertDatabaseFriend(new DatabaseFriend(2, 9, "le van Loc", "http://androidexample.com/media/webservice/LazyListView_images/image3.png",
				"pppp d", "073838383", "code sqlite",13));
		db.insertDatabaseFriend(new DatabaseFriend(2, 10, "dai_tien", "http://androidexample.com/media/webservice/LazyListView_images/image2.png",
				"lllll d", "073838383", "hoc viec", 15));
		
		Log.d("UPDATE", "-----UPDATE_ID AND FRIEND_ID-----------");
		db.updateDatabaseFriend(new DatabaseFriend(1,2, 10, "Le Loc", "http://androidexample.com/media/webservice/LazyListView_images/image2.png",
				"lllll d", "073838383", "hoc viec",3));
		db.updateDatabaseFriend(7);
		
		db.deleteFriendByRequestId(15);
		
		List<DatabaseFriend> mFriendList;
		mFriendList = db.getAllFriend();
		String info_friend="", info_request="";
		for (DatabaseFriend f : mFriendList) {
			info_friend += "ID: " + f.getId() + " userid: " + f.getUser_id() 
					+ " friend Id:" + f.getFriend_id() + " friendname: "
					+ f.getFriend_Name() + "__REquest_Id: "+f.getRequestId() +" \n";
		}
		Log.d("LIST FRIEND", info_friend);
		mFriendList = db.getAllFriendByUserId(2);
		for (DatabaseFriend f : mFriendList) {
			info_request += "ID: " + f.getId() + " userid: " + f.getUser_id() 
					+ " friend Id:" + f.getFriend_id() + " friendname: "
					+ f.getFriend_Name() + "__REquest_Id: "+f.getRequestId() +" \n";
		}
		Log.d("LIST FRIEND BY USERNAME", info_request);
	}
}
